<?php
namespace app\manager\controller;

use think\Controller;
use think\facade\Session;

class Base extends Controller
{
    public function initialize()
    {
        $admin_info = Session::get('admin_info');
        if(!$admin_info)
        {
            $this->redirect('account/login');
        }
    }

    public function uploadImage()
    {
        $file = request()->file('file');
        if($file)
        {
            $date = date('Ymd');
            $root_path = '../public/static/uploads/images/' . $date;
            $root_path = str_replace('\\', '/', $root_path);
            //大小限制 3M
            $info = $file->rule('uniqid')->validate(['size' => 3145728, 'ext' => 'jpg,png,gif,jpeg'])->move($root_path);
            if($info){
                $file_name = $info->getSaveName();
                $file_path = $root_path . '/' . $info->getSaveName();
                $data['src'] = '/static/uploads/images/'.$date.'/'.$file_name;
                return responseJson(0, '上传成功', $data);
            }else{
                return responseJson(400,'上传失败');
            }

        }
    }
}